define(["./http-lay", "./utils"], function(http, utils) {
    return {
        saveStorage(key) {
            let val;
            if (http.interactive("").getQueryString(key) !== null) {
                if (key === "token") {
                    val = http.interactive("").getQueryString(key);
                    http.storage().setItem(key, val)
                } else {
                    val = http.interactive("").getQueryString(key);
                    let tooVal = this.setAES(val);
                    http.storage().setItem(key, tooVal)
                }
                window.location.href = window.location.origin + window.location.pathname
            } else {
                if (key === "token") {
                    val = http.storage().getItem(key)
                } else {
                    if (key === "bazaarIds") {
                        val = this.getDAes(http.storage().getItem(key)).split(",");
                    } else {
                        val = this.getDAes(http.storage().getItem(key))
                    }
                }
            }
            return val
        },
        isArrayFn(value) {
            if (typeof Array.isArray === "function") {
                return Array.isArray(value);
            } else {
                return Object.prototype.toString.call(value) === "[object Array]";
            }
        },
        exitHandle($, target, keys, page) {
            $(document).on('click', `#${target}`, () => {
                $.each(keys, (index, item) => {
                    http.storage().removeItem(item)
                });
                window.open(page, "_self")
            })
        },
        transTime(time) {
            let dc = time.substring(0, 19).replace(/-/g, '/');
            let timestamp = new Date(dc).getTime();
            return timestamp
        },
        setAES(data) { //加密
            const key = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; //密钥
            const iv = '1234567812345678';
            let encrypted = utils.getAesString(data, key, iv); //密文
            //let encrypted1 = CryptoJS.enc.Utf8.parse(encrypted);
            return encrypted;
        },
        getDAes(data) { //解密
            const keys = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; //密钥
            const ivs = '1234567812345678';
            let decryptedStr = utils.getDAesString(data, keys, ivs);
            return decryptedStr;
        },
        handleStatus(val) { //判断状态
            let sta;
            switch (val) {
                case 0:
                    sta = "未提交";
                    break;
                case 5:
                    sta = "中心退回";
                    break;
                case 6:
                    sta = "待归档";
                    break;
                case 7:
                    sta = "审核归档";
                    break;
                default:
                    sta = "已审核"
            }
            return sta
        },
        getStatusVal(sta) { //判断状态
            let val;
            switch (sta) {
                case "未提交":
                    val = 0;
                    break;
                case "乡退回":
                    val = 1;
                    break;
                case "待乡审":
                    val = 2;
                    break;
                case "区退回":
                    val = 3;
                    break;
                case "待区审":
                    val = 4;
                    break;
                case "中心退回":
                    val = 5;
                    break;
                case "待归档":
                    val = 6;
                    break;
                case "审核归档":
                    val = 7;
                    break;
            }
            return val
        },
        serachIndexData(target, data, param) {
            let index = -1;
            data.map((item, key) => {
                if (item[param] === target) {
                    index = key;
                    return
                }
            });
            return index
        },
        tabConf(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '菜价交易情况',
                limit: 50,
                height: 'full-200',
                loading: true
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' }, { field: 'pkId', title: 'pkId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'shiChangId', title: 'shiChangId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'bazaarName', title: '市场名称', width: 100 }, { field: 'pinZhongId', title: 'pinZhongId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'typeName', title: '蔬菜名称', width: 90 }, { field: 'jiaoCai', title: '郊菜成交量(万公斤)', width: 160, sort: true, edit: true }, { field: 'waiCai', title: '外菜成交量(万公斤)', width: 160, edit: true }, { field: 'priceMax', title: '最高价(元/公斤)', width: 150, edit: true }, { field: 'priceLow', title: '最低价(元/公斤)', width: 150, sort: true, edit: true }, { field: 'pavg', title: '大宗价(元/公斤)', width: 130, edit: true }, { field: 'addtime', title: '上报时间', width: 150, sort: true }, { field: 'adduser', title: '录入人', width: 90 }, { field: 'state', title: '状态' }, { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabSta(data) {
            const tabCf = {
                elem: '#census',
                toolbar: '#toolCensus'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { field: 'name', title: '品种' }, { field: 'currentPeriod', title: '本期(元/公斤)' }, { field: 'priorPeriod', title: '上期(元/公斤)' }, { field: 'correspondPeriod', title: '同期(元/公斤)' }, { field: 'chainIndex', title: '环比' }, { field: 'correspondIndex', title: '同比' }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabOil(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' }, { field: 'pkId', title: 'pkId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'bazaarName', title: '市场名称' }, { field: 'pinZhongId', title: 'pinZhongId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'typeName', title: '粮油名称' }, { field: 'guiGe', title: '等级规格', sort: true, edit: true }, { field: 'danWei', title: '计量单位', edit: true }, { field: 'price', title: '批发价', edit: true }, { field: 'addtime', title: '上报时间', sort: true }, { field: 'adduser', title: '录入人' }, { field: 'state', title: '状态' }, { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabVol(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { field: 'bazaarName', title: '品种', rowspan: 2, align: 'center' }, { field: 'summary', title: '合计', colspan: 3, align: 'center' }, { field: 'bsz', title: '白沙洲', colspan: 3, align: 'center' }, { field: 'hjt', title: '皇经堂', colspan: 3, align: 'center' }, { field: 'sjm', title: '四季美', colspan: 3, align: 'center' }
                        // ,{field:'qs', title:'青石', colspan: 3, align:'center'}
                        // ,{field:'qsm', title:'青山', colspan: 3, align:'center'}
                        // ,{field:'hp', title:'黄浦', colspan: 3, align:'center'}
                        // ,{field:'hjx', title:'海吉星', colspan: 3, align:'center'}
                    ],
                    [
                        { field: 'suSums', title: '合计', align: 'center' }, { field: 'suSuburb', title: '郊菜', align: 'center' }, { field: 'suExternal', title: '外菜', align: 'center' }, { field: 'bszSums', title: '合计', align: 'center' }, { field: 'bszSuburb', title: '郊菜', align: 'center' }, { field: 'bszExternal', title: '外菜', align: 'center' }, { field: 'hjtSums', title: '合计', align: 'center' }, { field: 'hjtSuburb', title: '郊菜', align: 'center' }, { field: 'hjtExternal', title: '外菜', align: 'center' }, { field: 'sjmSums', title: '合计', align: 'center' }, { field: 'sjmSuburb', title: '郊菜', align: 'center' }, { field: 'sjmExternal', title: '外菜', align: 'center' }
                        // ,{field: 'qsSums', title: '合计'}
                        // ,{field: 'qsSuburb', title: '郊菜'}
                        // ,{field: 'qsExternal', title: '外菜'}
                        // ,{field: 'qsmSums', title: '合计'}
                        // ,{field: 'qsmSuburb', title: '郊菜'}
                        // ,{field: 'qsmExternal', title: '外菜'}
                        // ,{field: 'hpSums', title: '合计'}
                        // ,{field: 'hpSuburb', title: '郊菜'}
                        // ,{field: 'hpExternal', title: '外菜'}
                        // ,{field: 'hjxSums', title: '合计'}
                        // ,{field: 'hjxSuburb', title: '郊菜'}
                        // ,{field: 'hjxExternal', title: '外菜'}
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabAproduct(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' }, { field: 'pkId', title: 'pkId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'bazaarName', title: '市场名称' }, { field: 'pinZhongId', title: 'pinZhongId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'typeName', title: '水产名称' }, { field: 'guiGe', title: '等级规格', width: 160, sort: true, edit: true }, { field: 'priceMax', title: '最高价(元/公斤)', width: 160, edit: true }, { field: 'priceLow', title: '最低价(元/公斤)', width: 130, edit: true }, { field: 'addtime', title: '上报时间', width: 130, sort: true }, { field: 'adduser', title: '录入人', width: 80 }, { field: 'state', title: '状态' }, { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabliveStock(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' }, { field: 'pkId', title: 'pkId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'areaName', title: '行政单位' }, { field: 'pinZhongId', title: 'pinZhongId', fixed: 'left', unresize: true, sort: true, hide: true }, { field: 'typeName', title: '品种名称' }, { field: 'price', title: '交易价格(元/公斤)', sort: true, edit: true }, { field: 'addtime', title: '上报时间', sort: true }, { field: 'adduser', title: '录入人' }, { field: 'state', title: '状态' }, { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabVolExc(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 100,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { field: 'bazaarName', title: '品种', rowspan: 2, align: 'center' }, { field: 'currentIssue', title: '本期', colspan: 3, align: 'center' }, { field: 'Synchronization', title: '同期', colspan: 3, align: 'center' }, { field: 'YearOnYear', title: '同比', colspan: 3, align: 'center' }
                        // ,{field:'bsz', title:'白沙洲', colspan: 3, align:'center'}
                        // ,{field:'hjt', title:'皇经堂', colspan: 3, align:'center'}
                        // ,{field:'sjm', title:'四季美', colspan: 3, align:'center'}
                        // ,{field:'qs', title:'青石', colspan: 3, align:'center'}
                        // ,{field:'qsm', title:'青山', colspan: 3, align:'center'}
                        // ,{field:'hp', title:'黄浦', colspan: 3, align:'center'}
                        // ,{field:'hjx', title:'海吉星', colspan: 3, align:'center'}
                    ],
                    [
                        { field: 'ciSums', title: '合计', align: 'center' }, { field: 'ciSuburb', title: '郊菜', align: 'center' }, { field: 'ciExternal', title: '外菜', align: 'center' }, { field: 'siSums', title: '合计', align: 'center' }, { field: 'siSuburb', title: '郊菜', align: 'center' }, { field: 'siExternal', title: '外菜', align: 'center' }, { field: 'yoySums', title: '合计', align: 'center' }, { field: 'yoySuburb', title: '郊菜', align: 'center' }, { field: 'yoyExternal', title: '外菜', align: 'center' }
                        // ,{field: 'bszSums', title: '合计', align:'center'}
                        // ,{field: 'bszSuburb', title: '郊菜', align:'center'}
                        // ,{field: 'bszExternal', title: '外菜', align:'center'}
                        // ,{field: 'hjtSums', title: '合计', align:'center'}
                        // ,{field: 'hjtSuburb', title: '郊菜', align:'center'}
                        // ,{field: 'hjtExternal', title: '外菜', align:'center'}
                        // ,{field: 'sjmSums', title: '合计', align:'center'}
                        // ,{field: 'sjmSuburb', title: '郊菜', align:'center'}
                        // ,{field: 'sjmExternal', title: '外菜', align:'center'}
                        // ,{field: 'qsSums', title: '合计'}
                        // ,{field: 'qsSuburb', title: '郊菜'}
                        // ,{field: 'qsExternal', title: '外菜'}
                        // ,{field: 'qsmSums', title: '合计'}
                        // ,{field: 'qsmSuburb', title: '郊菜'}
                        // ,{field: 'qsmExternal', title: '外菜'}
                        // ,{field: 'hpSums', title: '合计'}
                        // ,{field: 'hpSuburb', title: '郊菜'}
                        // ,{field: 'hpExternal', title: '外菜'}
                        // ,{field: 'hjxSums', title: '合计'}
                        // ,{field: 'hjxSuburb', title: '郊菜'}
                        // ,{field: 'hjxExternal', title: '外菜'}
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        tabMutiExc(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 100,
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                limit: 50,
                height: 'full-200'
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { field: 'bazaarName', title: '品种', rowspan: 2, align: 'center' }, { field: 'currentIssue', title: '本期', colspan: 3, align: 'center' }, { field: 'Synchronization', title: '同期', colspan: 3, align: 'center' }, { field: 'YearOnYear', title: '同比', colspan: 3, align: 'center' }, { field: 'bsz', title: '白沙洲', colspan: 3, align: 'center' }, { field: 'hjt', title: '皇经堂', colspan: 3, align: 'center' }, { field: 'sjm', title: '四季美', colspan: 3, align: 'center' }
                        // ,{field:'qs', title:'青石', colspan: 3, align:'center'}
                        // ,{field:'qsm', title:'青山', colspan: 3, align:'center'}
                        // ,{field:'hp', title:'黄浦', colspan: 3, align:'center'}
                        // ,{field:'hjx', title:'海吉星', colspan: 3, align:'center'}
                    ],
                    [
                        { field: 'ciSums', title: '合计', align: 'center' }, { field: 'ciSuburb', title: '郊菜', align: 'center' }, { field: 'ciExternal', title: '外菜', align: 'center' }, { field: 'siSums', title: '合计', align: 'center' }, { field: 'siSuburb', title: '郊菜', align: 'center' }, { field: 'siExternal', title: '外菜', align: 'center' }, { field: 'yoySums', title: '合计', align: 'center' }, { field: 'yoySuburb', title: '郊菜', align: 'center' }, { field: 'yoyExternal', title: '外菜', align: 'center' }, { field: 'bszSums', title: '合计', align: 'center' }, { field: 'bszSuburb', title: '郊菜', align: 'center' }, { field: 'bszExternal', title: '外菜', align: 'center' }, { field: 'hjtSums', title: '合计', align: 'center' }, { field: 'hjtSuburb', title: '郊菜', align: 'center' }, { field: 'hjtExternal', title: '外菜', align: 'center' }, { field: 'sjmSums', title: '合计', align: 'center' }, { field: 'sjmSuburb', title: '郊菜', align: 'center' }, { field: 'sjmExternal', title: '外菜', align: 'center' }
                        // ,{field: 'qsSums', title: '合计'}
                        // ,{field: 'qsSuburb', title: '郊菜'}
                        // ,{field: 'qsExternal', title: '外菜'}
                        // ,{field: 'qsmSums', title: '合计'}
                        // ,{field: 'qsmSuburb', title: '郊菜'}
                        // ,{field: 'qsmExternal', title: '外菜'}
                        // ,{field: 'hpSums', title: '合计'}
                        // ,{field: 'hpSuburb', title: '郊菜'}
                        // ,{field: 'hpExternal', title: '外菜'}
                        // ,{field: 'hjxSums', title: '合计'}
                        // ,{field: 'hjxSuburb', title: '郊菜'}
                        // ,{field: 'hjxExternal', title: '外菜'}
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
        ergodicData(data) {
            let index;
            data.map((item) => {
                index = item
            });
            return index
        },
        testNull(target) {
            let val;
            if (target || target == 0) {
                val = target
            } else {
                val = null
            }
            return val
        },
        marketFilter(markets, data, params) {
            let arr = [];
            if (this.serachIndexData(markets[0] - 0, data, params) !== -1) {
                markets.map((item, index) => {
                    arr.push(data[this.serachIndexData(item - 0, data, params)])
                });
            } else {
                arr = data
            }
            return arr
        },
        pushMonth(time, index) {
            let year = time.getFullYear(),
                month = time.getMonth(),
                date;
            month = month < 10 ? '0' + month : month;
            if (index === 1) {
                date = '0' + index;
            } else {
                date = new Date(year, month, 0).getDate();
            }

            return `${year}-${month}-${date}`
        },
        verifyInput(form, opt) {
            switch (opt) {
                case "vegetable":
                    form.verify({ //自定义验证规则
                        "jiaoCai": function(value) {
                                if (value.length < 5) {
                                    return '标题至少得5个字符啊';
                                }
                            }
                            // ,pass: [
                            //   /^[\S]{6,12}$/
                            //   ,'密码必须6到12位，且不能出现空格'
                            // ]
                            // ,content: function(value){
                            //   layedit.sync(editIndex);
                            // }
                    });
                    break;
                case "grainOil":
                    form.verify({ //自定义验证规则
                        "jiaoCai": function(value) {
                                if (value.length < 5) {
                                    return '标题至少得5个字符啊';
                                }
                            }
                            // ,pass: [
                            //   /^[\S]{6,12}$/
                            //   ,'密码必须6到12位，且不能出现空格'
                            // ]
                            // ,content: function(value){
                            //   layedit.sync(editIndex);
                            // }
                    });
                    break;
                case "aquatic":
                    form.verify({ //自定义验证规则
                        "jiaoCai": function(value) {
                                if (value.length < 5) {
                                    return '标题至少得5个字符啊';
                                }
                            }
                            // ,pass: [
                            //   /^[\S]{6,12}$/
                            //   ,'密码必须6到12位，且不能出现空格'
                            // ]
                            // ,content: function(value){
                            //   layedit.sync(editIndex);
                            // }
                    });
                    break;
                case "liveStock":
                    form.verify({ //自定义验证规则
                        "jiaoCai": function(value) {
                                if (value.length < 5) {
                                    return '标题至少得5个字符啊';
                                }
                            }
                            // ,pass: [
                            //   /^[\S]{6,12}$/
                            //   ,'密码必须6到12位，且不能出现空格'
                            // ]
                            // ,content: function(value){
                            //   layedit.sync(editIndex);
                            // }
                    });
                    break;
            }
        },
        AreaIdToBazaarId(barId, type) {
            let areaId, bazaarId
            switch (type) {
                case "A":
                    areaId = barId[0];
                    bazaarId = null;
                    break;
                case "B":
                    areaId = null;
                    bazaarId = barId;
                    break;
                default:
                    areaId = null;
                    bazaarId = barId;
                    break;
            }
            return { areaId, bazaarId }
        },
        TransforPromise(func, action, obj) {
            let p;
            switch (action) {
                case "isRemove":
                    p = new Promise((resolve) => {
                        func(obj.$, obj.arr, obj.path, resolve);
                    });
                    break;
                case "isAdd":
                    p = new Promise((resolve) => {
                        func(obj.$, obj.arr, obj.path, resolve);
                    });
                    break;
                case "isExamine":
                    p = new Promise((resolve) => {
                        func(obj.$, obj.arr, obj.path, resolve);
                    });
                    break;
            }
            return p
        },
        TransDateout(time) {
            return time = time > 9 ? time : "0" + time
        },
        handleDate(date) {
            const dt = new Date()
            return `${date}:${this.TransDateout(dt.getSeconds())}`
        },
        addtoSec(date) {
            const dt = new Date()
            return `${date} ${this.TransDateout(dt.getHours())}:${this.TransDateout(dt.getMinutes())}:${this.TransDateout(dt.getSeconds())}`
        },
        isTimeNow(date) {
            let y = date.getFullYear();
            let m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            let d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            let minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            let second = date.getSeconds();
            second = second < 10 ? ('0' + second) : second;
            return `${y}-${m}-${d} ${h}:${minute}:${second}`
        },
        tabUser(data) {
            const tabCf = {
                elem: '#test',
                cellMinWidth: 80,
                toolbar: '#toolbarDemo',
                title: '账户信息列表',
                limit: 50,
                height: 'full-200',
                loading: true
                    //,size: "sm"
                    ,
                cols: [
                    [
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'id', title: 'id', fixed: 'left', unresize: true, sort: true, hide: true },
                        { field: 'bazaarIds', title: 'bazaarIds', fixed: 'left', unresize: true, sort: true, hide: true },
                        { field: 'userName', title: '账号' },
                        { field: 'byName ', title: '用户名', fixed: 'left', unresize: true, sort: true, hide: true },
                        { field: 'roleName', title: '角色名' },
                        { field: 'type', title: '角色类型', sort: true, edit: true },
                        { field: 'capacityIds', title: '权限范围', edit: true },
                        { fixed: 'right', title: '操作', toolbar: '#barDemo' }
                    ]
                ],
                data: data,
                page: true
            };
            return tabCf
        },
    }
});